package com.easylinkin.linkappapi.meterbilling.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.easylinkin.linkappapi.common.model.RequestModel;
import com.easylinkin.linkappapi.meterbilling.entity.BaseBilling;
import com.easylinkin.linkappapi.meterbilling.entity.ext.BaseBillingExt;
import com.easylinkin.linkappapi.meterbilling.service.BillingStandardService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import site.morn.rest.RestBuilders;
import site.morn.rest.RestMessage;

import javax.annotation.Resource;
import java.util.List;

/**
 * class info :仪表计费标准
 *
 * @author liuqihang
 * @date 2021/7/12 16:10
 */
@Api(tags={"仪表计费标准控制器"})
@RestController
@RequestMapping("/billingStandard")
@Slf4j
public class BillingStandardController {

    @Resource
    private BillingStandardService billingStandardService;

    @ApiOperation("新增")
    @PostMapping("save")
    public RestMessage save(@RequestBody BaseBilling baseBilling) {
        Assert.notNull(baseBilling, "计费数据不能为空");
        String result = billingStandardService.saveBillingStandardData(baseBilling);
        if(result != null){
            return RestBuilders.failureBuilder().message(result).build();
        }
        return RestBuilders.successBuilder().message("success").build();
    }

    @ApiOperation("修改")
    @PostMapping("update")
    public RestMessage update(@RequestBody BaseBilling baseBilling) {
        Assert.notNull(baseBilling, "计费数据不能为空");
        String result = billingStandardService.updateBillingStandardData(baseBilling);
        if(result != null){
            return RestBuilders.failureBuilder().message(result).build();
        }
        return RestBuilders.successBuilder().message("success").build();
    }

    @ApiOperation("分页查询")
    @PostMapping("getPage")
    public RestMessage getPage(@RequestBody RequestModel<BaseBilling> requestModel) {
        Assert.notNull(requestModel, "requestModel 不能为空");
        Assert.notNull(requestModel.getPage(), "page 不能为空");
        Assert.notNull(requestModel.getCustomQueryParams(), "customQueryParams 不能为空");
        IPage<BaseBillingExt> baseBillingList = billingStandardService.getBaseBillingList(requestModel.getPage(), requestModel.getCustomQueryParams());
        return RestBuilders.successBuilder().data(baseBillingList).build();
    }

    @ApiOperation("删除")
    @PostMapping("delete")
    public RestMessage delete(@RequestBody BaseBilling baseBilling) {
        Assert.notNull(baseBilling, "计费数据不能为空");
        String result = billingStandardService.deleteBillingStandardData(baseBilling);
        if(result != null){
            return RestBuilders.failureBuilder().message(result).build();
        }
        return RestBuilders.successBuilder().message("success").build();
    }

    @ApiOperation("根据仪表类型获取基础费用")
    @PostMapping("getBaseBillingByMeterType")
    public RestMessage getBaseBillingByMeterType(@RequestBody BaseBilling baseBilling) {
        Assert.notNull(baseBilling, "page 不能为空");
        List<BaseBillingExt> baseBillingList = billingStandardService.getBaseBillingByMeterType(baseBilling);
        return RestBuilders.successBuilder().data(baseBillingList).build();
    }

}
